/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.bus.service;

import java.util.List;

import com.thinkgem.jeesite.common.utils.IdGen;
import com.thinkgem.jeesite.modules.bus.entity.VaccineInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.service.CrudService;
import com.thinkgem.jeesite.modules.bus.entity.EntDic;
import com.thinkgem.jeesite.modules.bus.dao.EntDicDao;

/**
 * 业务表关联字典项表Service
 * @author mengying
 * @version 2019-05-29
 */
@Service
@Transactional(readOnly = true)
public class EntDicService extends CrudService<EntDicDao, EntDic> {

	@Autowired
	private EntDicDao entDicDao;
	public EntDic get(String id) {
		return super.get(id);
	}
	
	public List<EntDic> findList(EntDic entDic) {
		return super.findList(entDic);
	}
	
	public Page<EntDic> findPage(Page<EntDic> page, EntDic entDic) {
		return super.findPage(page, entDic);
	}
	
	@Transactional(readOnly = false)
	public void save(EntDic entDic) {
		super.save(entDic);
	}
	
	@Transactional(readOnly = false)
	public void delete(EntDic entDic) {
		super.delete(entDic);
	}

	/***
	 * @Author zhangxingliang
	 * @Description 删除养殖场养殖品种数据
	 * @Date 19:15 2019/6/3
	 * @Param [tableId, tableName, dicInfoCode]
	 * @return void
	 **/
	@Transactional(readOnly = false)
	public void deleteByTableIdAndCode(String tableId,String tableName, String dicTypeId) {
		this.entDicDao.deleteByTableIdAndCode(tableId,tableName,dicTypeId);
	}

	/**
	 * @author Zhang Xingliang
	 * @description 保存存栏量
	 * @date 11:53 2019/6/25
	 * @params [entDicList, tableId, tableName, isNewRecord]
	 * @return void
	 **/
	public void save(List<EntDic> entDicList, String tableId, String tableName) {
		this.deleteByTableIdAndCode(tableId, tableName, "animalType");
		for (EntDic entDic : entDicList) {
			entDic.setIsNewRecord(true);
			entDic.setId(IdGen.nextId());
			entDic.setTableId(tableId);
			entDic.setTableName(tableName);
			this.save(entDic);
		}
	}
}